package com.zzyl.controller;


import com.aliyun.iot20180120.models.QueryBatchRegisterDeviceStatusResponseBody;
import com.aliyun.iot20180120.models.QueryDevicePropertyStatusResponseBody;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "设备管理")
@RequestMapping("/iot")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;



    @PostMapping("/syncProductList")
    public ResponseResult getDeviceInfo(){
         deviceService.getDeviceInfo();
        return ResponseResult.success();
    }

    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> getAllProduct(){
        List<ProductVo> productVos = deviceService.getAllProduct();
        return ResponseResult.success(productVos);
    }

    @PostMapping("/RegisterDevice")
    public ResponseResult registerDevice(@RequestBody DeviceDto deviceDto){
        deviceService.registerDevice(deviceDto);
        return ResponseResult.success();
    }

    @GetMapping("/pageQueryDevice")
    public ResponseResult<PageResponse<DeviceVo>> pageQueryDevice(DevicePageQueryDto devicePageQueryDto){
    PageResponse<DeviceVo> deviceVoPageResponse = deviceService.pageQueryDevice(devicePageQueryDto);
      return ResponseResult.success(deviceVoPageResponse);
    }

    @PostMapping("/QueryDeviceDetail")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody DeviceDto deviceDto){
        DeviceVo deviceVo = deviceService.queryDeviceDetail(deviceDto);
        return ResponseResult.success(deviceVo);
    }
    @PostMapping("/QueryDevicePropertyStatus")
    public ResponseResult<HashMap<String, QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyDataList>> queryDevicePropertyStatus(@RequestBody DeviceDto deviceDto){
        HashMap<String, QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyDataList> map = deviceService.queryDevicePropertyStatus(deviceDto);
        return ResponseResult.success(map);
    }
    @PostMapping("QueryThingModelPublished")
    public ResponseResult<Map<String,String>> queryThingModelPublished(@RequestBody DeviceDto deviceDto){
        Map<String,String>map = deviceService.queryThingModelPublished(deviceDto);
        return ResponseResult.success(map);
    }
    @PostMapping("/UpdateDevice")
    public ResponseResult updateDevice(@RequestBody DeviceDto deviceDto){
        deviceService.updateDevice(deviceDto);
        return ResponseResult.success();
    }
    @DeleteMapping("/DeleteDevice")
    public ResponseResult deleteDevice(@RequestBody DeviceDto deviceDto){
        deviceService.deleteDevice(deviceDto);
        return ResponseResult.success();
    }
}
